package com.lemon.smartsafetynew.ui.adapter.hidden;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenBo;
import com.lemon.smartsafetynew.entity.hidden.SafeHiddenDownloadVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * @deprecated
 * Created by Andrew on 2017/9/25.
 */

public class SafeHiddenUploadHiddenListAdapter extends LemonRcvAdapter<SafeHiddenDownloadVo> {

    private RecyclerTClickListener<SafeHiddenDownloadVo> mListener;

    public SafeHiddenUploadHiddenListAdapter(@Nullable List<SafeHiddenDownloadVo> data,
                                             RecyclerTClickListener<SafeHiddenDownloadVo> mListener) {
        super(data);
        this.mListener = mListener;
    }

    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<SafeHiddenDownloadVo> {

        private SafeHiddenDownloadVo mData;

        @Bind(R.id.safe_hidden_item_name_tv)
        TextView safeHiddenItemNameTv;
        @Bind(R.id.safe_hidden_item_tv)
        TextView safeHiddenItemTv;
        @Bind(R.id.safe_hidden_item_layout)
        LinearLayout safeHiddenItemLayout;
        @Bind(R.id.safe_hidden_department_name_tv)
        TextView safeHiddenDepartmentNameTv;
        @Bind(R.id.safe_hidden_department_tv)
        TextView safeHiddenDepartmentTv;
        @Bind(R.id.safe_hidden_department_layout)
        LinearLayout safeHiddenDepartmentLayout;
        @Bind(R.id.safe_hidden_person_name_tv)
        TextView safeHiddenPersonNameTv;
        @Bind(R.id.safe_hidden_person_tv)
        TextView safeHiddenPersonTv;
        @Bind(R.id.safe_hidden_person_layout)
        LinearLayout safeHiddenPersonLayout;
        @Bind(R.id.safe_hidden_close_time_name_tv)
        TextView safeHiddenCloseTimeNameTv;
        @Bind(R.id.safe_hidden_close_time_tv)
        TextView safeHiddenCloseTimeTv;
        @Bind(R.id.safe_hidden_close_time_layout)
        LinearLayout safeHiddenCloseTimeLayout;
        @Bind(R.id.right_top_imageView)
        ImageView rightTopImageView;
        @Bind(R.id.safe_hidden_layout)
        LinearLayout safeHiddenLayout;
        @Bind(R.id.main_card_view)
        CardView mainCardView;
        @Bind(R.id.right_bottom_imageView)
        ImageView rightBottomImageView;
        @Bind(R.id.choose_imageView)
        ImageView chooseImageView;

        @Override
        public int getLayoutResId() {
            return R.layout.item_safe_hidden;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            safeHiddenLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    chooseImageView.setSelected(!chooseImageView.isSelected());
                    if(chooseImageView.isSelected()) {
                        mListener.onItemClick(mData, SafeHiddenBo.Select.selected.getValue());
                    } else {
                        mListener.onItemClick(mData, SafeHiddenBo.Select.not_selected.getValue());
                    }
                }
            });
        }

        @Override
        public void handleData(SafeHiddenDownloadVo safeHiddenDownloadVo, int position) {

            mData = safeHiddenDownloadVo;

            chooseImageView.setVisibility(View.VISIBLE);

            if (SafeHiddenBo.Status.rectify.getValue().equals(safeHiddenDownloadVo.getStatus())) {        //待整改

                safeHiddenCloseTimeLayout.setVisibility(View.GONE);
                safeHiddenItemTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getName()));
                safeHiddenDepartmentNameTv.setText("当前部门：");
                safeHiddenDepartmentTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getRectify_dept()));
                safeHiddenPersonNameTv.setText("当前处理人：");
                safeHiddenPersonTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getRectify_user_name()));

            } else if (SafeHiddenBo.Status.review.getValue().equals(safeHiddenDownloadVo.getStatus())) {  //待复查

                safeHiddenCloseTimeLayout.setVisibility(View.GONE);

                safeHiddenItemTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getName()));
                safeHiddenDepartmentNameTv.setText("当前部门：");
                safeHiddenDepartmentTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getReview_dept()));
                safeHiddenPersonNameTv.setText("当前处理人：");
                safeHiddenPersonTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getReview_user_name()));

            } else if (SafeHiddenBo.Status.finish.getValue().equals(safeHiddenDownloadVo.getStatus())) {  //结束（已关闭--全部）

                safeHiddenCloseTimeLayout.setVisibility(View.VISIBLE);

                safeHiddenItemTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getName()));
                safeHiddenDepartmentNameTv.setText("责任部门：");
                safeHiddenDepartmentTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getReview_dept()));
                safeHiddenPersonNameTv.setText("责 任 人：");
                safeHiddenPersonTv.setText(CommonUtil.avoidNullString(safeHiddenDownloadVo.getReview_user_name()));
                safeHiddenCloseTimeNameTv.setText("关闭时间：");
                safeHiddenCloseTimeTv.setText(CommonUtil.secondToTimeStr(safeHiddenDownloadVo.getReview_time(), DateTypeEnum.DAY));
            }

        }
    }
}
